package hello;

/**
 * Created with IntelliJIDEA.
 * Description:
 * User: ASUS
 * Date: 2025/8/30
 * Time: 20:40
 */
import java.util.Arrays;

public class TwoDArrayExample {
    public static void main(String[] args) {
        // 创建一个 3x4 的二维数组
        int[][] matrix = {
                {1, 2, 3, 4},
                {5, 6, 7, 8},
                {9, 10, 11, 12}
        };

        // 访问元素
        System.out.println("第2行第3列的元素是: " + matrix[1][2]); // 输出: 7

        // 遍历二维数组
        System.out.println("矩阵所有元素:");
        for (int i = 0; i < matrix.length; i++) { // 遍历行
            for (int j = 0; j < matrix[i].length; j++) { // 遍历列
                System.out.print(matrix[i][j] + "\t");
            }
            System.out.println();
        }

        // 打印二维数组
        System.out.println("使用 deepToString 打印: " + Arrays.deepToString(matrix));
    }
}
